(function() {

var Bible = Class.extend({
	init: function() {
		this.list = [];
	},
	
	// public
	getList: function() {
		if (this.list.length == 0) {
			this._loadList();
		}
		return this.list;
	},
	getBible: function(vcode) {
		if (this.list.length == 0) {
			this._loadList();
		}
		return this._findBible(vcode);
	},
	
	// private
	_loadList: function() {
		var self = this;
		$.ajax({
			url: "/data/versions",
			async: false,
			success: function(data) {
				var list = $.parseJSON(data);
				list.pop();
				self.list = list;
			}
		});
	},
	_findBible: function(vcode) {
		for (var i = 0 ; i < this.list.length ; i++) {
			if (this.list[i].vcode == vcode) {
				return this.list[i];
			}
		}
		return null;
	}
});


holybible.model.Bible = {
	instance: null,
	getInstance: function() {
		if (!this.instance) {
			this.instance = new Bible();
		}
		return this.instance;
	}
};

})();
